package com.oamic.sdk.picker.pickerview.view;

import android.view.View;

import com.oamic.sdk.picker.R;
import com.oamic.sdk.picker.pickerview.adapter.ArrayWheelAdapter;
import com.oamic.sdk.picker.pickerview.adapter.NumericWheelAdapter;
import com.oamic.sdk.picker.pickerview.entity.DayModel;
import com.oamic.sdk.picker.pickerview.listener.ISelectTimeCallback;
import com.oamic.sdk.picker.pickerview.utils.DateUtil;
import com.oamic.sdk.picker.wheelview.adapter.WheelAdapter;
import com.oamic.sdk.picker.wheelview.listener.OnItemSelectedListener;
import com.oamic.sdk.picker.wheelview.view.WheelView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;


public class WheelTimeWithWeek {
    public static DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm");
    private View view;
    private WheelView mWvYear;
    private WheelView mWvMonth;
    private WheelView mWvDay;
    private WheelView wv_hours;
    private WheelView wv_minutes;
    private WheelView wv_seconds;
    private int gravity;

    private NumericWheelAdapter mYearAdapter;
    private NumericWheelAdapter mMonthAdapter;
    private WheelAdapter mDayAdapter;
    private NumericWheelAdapter mHoursAdapter;
    private NumericWheelAdapter mMinutesAdapter;
    private NumericWheelAdapter mSecondAdapter;


    private boolean dayIsShowWeek;//日期显示星期出来 默认不显示  显示星期的时候不会显示日期的label

    /**
     * 是否显示年、月、日、时、分、秒，固定长度6
     */
    private boolean[] type;
    private static final int DEFAULT_START_YEAR = 1900;
    private static final int DEFAULT_END_YEAR = 2100;
    private static final int DEFAULT_START_MONTH = 1;
    private static final int DEFAULT_END_MONTH = 12;
    private static final int DEFAULT_START_DAY = 1;
    private static final int DEFAULT_END_DAY = 31;
    private static final int DEFAULT_START_HOURS = 0;
    private static final int DEFAULT_END_HOURS = 23;
    private static final int DEFAULT_START_MINUTES = 0;
    private static final int DEFAULT_END_MINUTES = 59;
    private static final int DEFAULT_START_SECONDS = 0;
    private static final int DEFAULT_END_SECONDS= 59;

    //    private int startYear = DEFAULT_START_YEAR;
//    private int endYear = DEFAULT_END_YEAR;
//    private int startMonth = DEFAULT_START_MONTH;
//    private int endMonth = DEFAULT_END_MONTH;
//    private int startDay = DEFAULT_START_DAY;
//    private int endDay = DEFAULT_END_DAY; //表示31天的
//    private int currentYear;
//    private int currentMonth;
//    private int currentDay;
//    private int currentHours;
//    private int currentMinutes;
    private int position = 0;

    private int textSize;

    private boolean isLunarCalendar = false;
    private ISelectTimeCallback mSelectChangeCallback;
    private DayModel dayModel;

    // 添加大小月月份并将其转换为list,方便之后的判断
    private static String[] months_big = {"1", "3", "5", "7", "8", "10", "12"};
    private static String[] months_little = {"4", "6", "9", "11"};
    private final List<String> list_big = Arrays.asList(months_big);
    private final List<String> list_little = Arrays.asList(months_little);


    public WheelTimeWithWeek(View view, boolean[] type, int gravity, int textSize) {
        super();
        this.view = view;
        this.type = type;
        this.gravity = gravity;
        this.textSize = textSize;
    }

    public void setDayIsShowWeek(boolean dayIsShowWeek) {
        this.dayIsShowWeek = dayIsShowWeek;
    }

    public void setLunarMode(boolean isLunarCalendar) {
        this.isLunarCalendar = isLunarCalendar;
    }

    public boolean isLunarMode() {
        return isLunarCalendar;
    }


    public void setPicker(int year, final int month, int day, int h, int m, int s) {

    }


    //设置年列表
    private void resetYearWheelView() {
        int startYear = getStartYear();
        int endYear = getEndYear();
        mWvYear = (WheelView) view.findViewById(R.id.sdk_year);
        mYearAdapter = new NumericWheelAdapter(startYear, endYear);
        mWvYear.setAdapter(mYearAdapter);// 设置"年"的显示数据
        mWvYear.setGravity(gravity);
        mWvYear.setCurrentItem(0);
    }

    //设置月列表
    private void resetMonthWheelView() {
        mWvMonth = (WheelView) view.findViewById(R.id.sdk_month);

        int currentSelectYear = mYearAdapter.getItem(mWvYear.getCurrentItem());
        int startMonth = getStartMonth(currentSelectYear);
        int endMonth = getEndMonth(currentSelectYear);

        mMonthAdapter = new NumericWheelAdapter(startMonth, endMonth);

        mWvMonth.setAdapter(mMonthAdapter);
        mWvMonth.setGravity(gravity);
        mWvMonth.setCurrentItem(0);
    }

    //设置日列表
    private void resetDayWheelView() {
        mWvDay = (WheelView) view.findViewById(R.id.sdk_day);
        if (dayIsShowWeek) {
            int minDay = getMinDay();
            int maxDay = getMaxDay();
            mDayAdapter = new ArrayWheelAdapter(getSolarDayWeekList(minDay, maxDay));
            mWvDay.setAdapter(mDayAdapter);
        } else {
            int currentSelectYear = mYearAdapter.getItem(mWvYear.getCurrentItem());
            int currentSelectMonth = mMonthAdapter.getItem(mWvMonth.getCurrentItem());
            int startDay = getStartDay(currentSelectYear, currentSelectMonth);
            int endDay = getEndDay(currentSelectYear, currentSelectMonth);
            mDayAdapter = new NumericWheelAdapter(startDay, endDay);
            mWvDay.setAdapter(mDayAdapter);
        }
        mWvDay.setGravity(gravity);
        mWvDay.setCurrentItem(0);
    }

    //设置小时列表
    private void resetHoursWheelView() {
        wv_hours = (WheelView) view.findViewById(R.id.sdk_hour);
        int currentSelectYear = mYearAdapter.getItem(mWvYear.getCurrentItem());
        int currentSelectMonth = mMonthAdapter.getItem(mWvMonth.getCurrentItem());
        Object selectDay = mDayAdapter.getItem(mWvDay.getCurrentItem());
        int day;
        if (selectDay instanceof DayModel) {
            day = ((DayModel) selectDay).getDay();
        } else {
            day = (int) selectDay;
        }
        int startHours = getStartHours(currentSelectYear, currentSelectMonth, day);
        int endHours = getEndHours(currentSelectYear, currentSelectMonth, day);
        mHoursAdapter = new NumericWheelAdapter(startHours, endHours);
        wv_hours.setAdapter(mHoursAdapter);
        wv_hours.setGravity(gravity);
        wv_hours.setCurrentItem(0);
    }

    //设置分钟列表
    private void resetMinutesWheelView() {
        wv_minutes = (WheelView) view.findViewById(R.id.sdk_min);
        int currentSelectYear = mYearAdapter.getItem(mWvYear.getCurrentItem());
        int currentSelectMonth = mMonthAdapter.getItem(mWvMonth.getCurrentItem());
        Object currentSelectDay = mDayAdapter.getItem(mWvDay.getCurrentItem());
        int selectHours = mHoursAdapter.getItem(wv_hours.getCurrentItem());
        int day;
        if (currentSelectDay instanceof DayModel) {
            day = ((DayModel) currentSelectDay).getDay();
        } else {
            day = (int) currentSelectDay;
        }
        int startMinutes = getStartMinutes(currentSelectYear, currentSelectMonth, day,selectHours);
        int endMinutes = getEndMinutes(currentSelectYear, currentSelectMonth, day,selectHours);
        mMinutesAdapter = new NumericWheelAdapter(startMinutes, endMinutes);
        wv_minutes.setAdapter(mMinutesAdapter);
        wv_minutes.setGravity(gravity);
        wv_minutes.setCurrentItem(0);
    }

    //设置秒列表
    private void resetSecondsWheelView() {
        wv_seconds = (WheelView) view.findViewById(R.id.sdk_second);
        int currentSelectYear = mYearAdapter.getItem(mWvYear.getCurrentItem());
        int currentSelectMonth = mMonthAdapter.getItem(mWvMonth.getCurrentItem());
        Object currentSelectDay = mDayAdapter.getItem(mWvDay.getCurrentItem());
        int currentHours = mHoursAdapter.getItem(wv_hours.getCurrentItem());
        int day;
        if (currentSelectDay instanceof DayModel) {
            day = ((DayModel) currentSelectDay).getDay();
        } else {
            day = (int) currentSelectDay;
        }
        int selectMinutes = mMinutesAdapter.getItem(wv_minutes.getCurrentItem());
        int startSeconds =getStartSeconds(currentSelectYear, currentSelectMonth, day,currentHours,selectMinutes);
        int endSeconds = getEndSeconds(currentSelectYear, currentSelectMonth, day,currentHours,selectMinutes);
        mSecondAdapter = new NumericWheelAdapter(startSeconds, endSeconds);
        wv_seconds.setAdapter(mSecondAdapter);
        wv_seconds.setGravity(gravity);
        wv_seconds.setCurrentItem(0);
    }

    public void setSelectDate(Calendar calendar) {

        int year, month, day, hours, minute, seconds;
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH) + 1;
        day = calendar.get(Calendar.DAY_OF_MONTH);
        hours = calendar.get(Calendar.HOUR_OF_DAY);
        minute = calendar.get(Calendar.MINUTE);
        seconds = calendar.get(Calendar.SECOND);

        mWvYear.setCurrentItem(mYearAdapter.indexOf(year));// 初始化时显示的数据

        mWvMonth.setCurrentItem(mMonthAdapter.indexOf(month));

        if (dayIsShowWeek) {
            int index = ((ArrayWheelAdapter) mDayAdapter).indexOf(new DayModel(year, month, day));
            mWvDay.setCurrentItem(index);
        } else {
            mWvDay.setCurrentItem(mDayAdapter.indexOf(day));
        }

        wv_hours.setCurrentItem(mHoursAdapter.indexOf(hours));

        wv_minutes.setCurrentItem(mMinutesAdapter.indexOf(minute));

        wv_seconds.setCurrentItem(mSecondAdapter.indexOf(seconds));
    }

    /**
     * 是否闰年
     *
     * @param year
     * @return
     */
    public boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }

    //设置年监听
    private void setYearListener() {
        mWvYear.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                resetMonthWheelView();
                resetDayWheelView();
//                resetHoursWheelView();
//                resetMinutesWheelView();
//                resetSecondsWheelView();
                if (mSelectChangeCallback != null) {
                    mSelectChangeCallback.onTimeSelectChanged();
                }
            }
        });
    }

    //设置月监听
    private void setMonthListener() {
        mWvMonth.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                resetDayWheelView();
//                resetHoursWheelView();
//                resetMinutesWheelView();
//                resetSecondsWheelView();
                if (mSelectChangeCallback != null) {
                    mSelectChangeCallback.onTimeSelectChanged();
                }
            }
        });
    }

    //设置日监听
    private void setDayListener() {
        mWvDay.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                resetHoursWheelView();
                resetMinutesWheelView();
                resetSecondsWheelView();
            }
        });
    }

    private void setHoursListener() {
        wv_hours.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                resetMinutesWheelView();
                resetSecondsWheelView();
            }
        });
    }

    private void setMinutesListener() {
        wv_minutes.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                resetSecondsWheelView();
            }
        });
    }


    /**
     * 设置公历
     */
    private void initSolarView() {
        // 年
        resetYearWheelView();
        // 月
        resetMonthWheelView();
        // 日
        resetDayWheelView();

        //时
        resetHoursWheelView();
        //分
        resetMinutesWheelView();
        //秒
        resetSecondsWheelView();

        // 添加"年"监听
        setYearListener();

        // 添加"月"监听
        setMonthListener();

        //添加"日"监听
        setDayListener();
        setHoursListener();
        setMinutesListener();

        if (type.length != 6) {
            throw new IllegalArgumentException("type[] length is not 6");
        }
        mWvYear.setVisibility(type[0] ? View.VISIBLE : View.GONE);
        mWvMonth.setVisibility(type[1] ? View.VISIBLE : View.GONE);
        mWvDay.setVisibility(type[2] ? View.VISIBLE : View.GONE);
        wv_hours.setVisibility(type[3] ? View.VISIBLE : View.GONE);
        wv_minutes.setVisibility(type[4] ? View.VISIBLE : View.GONE);
        wv_seconds.setVisibility(type[5] ? View.VISIBLE : View.GONE);
        setContentTextSize();
    }


    //获取当前日
    private Calendar getCurrentDay() {
        Calendar currentCalendar = Calendar.getInstance();
        currentCalendar.setTimeInMillis(System.currentTimeMillis());
        currentCalendar.set(Calendar.HOUR_OF_DAY, 0);
        currentCalendar.set(Calendar.MINUTE, 0);
        currentCalendar.set(Calendar.SECOND, 0);
        currentCalendar.set(Calendar.MILLISECOND, 0);
        return currentCalendar;
    }

    //获取日期范围
    private int getMinDay() {
        int minDay;
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTimeInMillis(mStartDate.getTime().getTime());
        startCalendar.set(Calendar.HOUR_OF_DAY, 0);
        startCalendar.set(Calendar.MINUTE, 0);
        startCalendar.set(Calendar.SECOND, 0);
        startCalendar.set(Calendar.MILLISECOND, 0);

        long bTime = Math.abs((startCalendar.getTime().getTime() - getCurrentDay().getTime().getTime()));
        minDay = (int) Math.abs(bTime / ((1000 * 60 * 60 * 24)));
        if (startCalendar.getTimeInMillis() < getCurrentDay().getTimeInMillis()) {
            minDay = -minDay;
        }
        return minDay;
    }

    //获取日期范围
    private int getMaxDay() {
        int maxDay;
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTimeInMillis(mEndDate.getTime().getTime());
        endCalendar.set(Calendar.HOUR_OF_DAY, 0);
        endCalendar.set(Calendar.MINUTE, 0);
        endCalendar.set(Calendar.SECOND, 0);
        endCalendar.set(Calendar.MILLISECOND, 0);

        long bTime = Math.abs((endCalendar.getTime().getTime() - getCurrentDay().getTime().getTime()));
        maxDay = (int) Math.abs(bTime / ((1000 * 60 * 60 * 24)));
        if (endCalendar.getTimeInMillis() < getCurrentDay().getTimeInMillis()) {
            maxDay = -maxDay;
        }
        return maxDay;
    }

    /**
     * 设置公历的日期适配器
     *
     * @param year
     * @param month
     * @param startDay
     * @param endDay
     */
    private void setSolarDayAdapter(int year, int month, int startDay, int endDay) {
        int minDay = getMinDay();
        int maxDay = getMaxDay();
        if (dayIsShowWeek) {
            mWvDay.setAdapter(new ArrayWheelAdapter(getSolarDayWeekList(minDay, maxDay)));
        } else {
            mWvDay.setAdapter(new NumericWheelAdapter(startDay, endDay));
        }

    }


    /**
     * 显示星期数 获取公历的日期列表数据
     *
     * @param maxDays
     * @return
     */
    private List<DayModel> getSolarDayWeekList(int minDays, int maxDays) {
        if (minDays > maxDays) {
            return new ArrayList<>();
        }
        List<DayModel> dayWeekList = new ArrayList<>();
        int day;
        Calendar calendar = Calendar.getInstance();
        long time = System.currentTimeMillis() + (24 * 60 * 60 * 1000L * minDays);
        calendar.setTimeInMillis(time);
        int days = minDays, month;
        int year;
        do {
            if (days > (minDays)) {
                calendar.add(Calendar.DAY_OF_MONTH, 1);
            }
            year = calendar.get(Calendar.YEAR);
            month = calendar.get(Calendar.MONTH) + 1;
            day = calendar.get(Calendar.DAY_OF_MONTH);
            String week = DateUtil.weekToStrCN(calendar.get(Calendar.DAY_OF_WEEK));
            if (days == 0) {
                dayWeekList.add(new DayModel(year, month, day, "今日"));
            } else {
                dayWeekList.add(new DayModel(year, month, day, String.format("%d月%d日%s", month, day, week)));
            }
            days++;
        } while (days <= maxDays);

        return dayWeekList;
    }


    private void setContentTextSize() {
        mWvDay.setTextSize(textSize);
        mWvMonth.setTextSize(textSize);
        mWvYear.setTextSize(textSize);
        wv_hours.setTextSize(textSize);
        wv_minutes.setTextSize(textSize);
        wv_seconds.setTextSize(textSize);
    }

    //设置后缀
    public void setLabels(String label_year, String label_month, String label_day, String label_hours, String label_mins, String label_seconds) {
        if (isLunarCalendar) {
            return;
        }

        if (label_year != null) {
            mWvYear.setLabel(label_year);
        } else {
            mWvYear.setLabel(view.getContext().getString(R.string.pickerview_year));
        }
        if (label_month != null) {
            mWvMonth.setLabel(label_month);
        } else {
            mWvMonth.setLabel(view.getContext().getString(R.string.pickerview_month));
        }
        if (label_day != null) {
            mWvDay.setLabel(label_day);
        } else {
            mWvDay.setLabel(view.getContext().getString(R.string.pickerview_day));
        }
        if (label_hours != null) {
            wv_hours.setLabel(label_hours);
        } else {
            wv_hours.setLabel(view.getContext().getString(R.string.pickerview_hours));
        }
        if (label_mins != null) {
            wv_minutes.setLabel(label_mins);
        } else {
            wv_minutes.setLabel(view.getContext().getString(R.string.pickerview_minutes));
        }
        if (label_seconds != null) {
            wv_seconds.setLabel(label_seconds);
        } else {
            wv_seconds.setLabel(view.getContext().getString(R.string.pickerview_seconds));
        }

    }

    //设置偏移量,形成椭圆效果
    public void setTextXOffset(int x_offset_year, int x_offset_month, int x_offset_day,
                               int x_offset_hours, int x_offset_minutes, int x_offset_seconds) {
        mWvYear.setTextXOffset(x_offset_year);
        mWvMonth.setTextXOffset(x_offset_month);
        mWvDay.setTextXOffset(x_offset_day);
        wv_hours.setTextXOffset(x_offset_hours);
        wv_minutes.setTextXOffset(x_offset_minutes);
        wv_seconds.setTextXOffset(x_offset_seconds);
    }

    /**
     * 设置是否循环滚动
     *
     * @param cyclic
     */
    public void setCyclic(boolean cyclic) {
        mWvYear.setCyclic(cyclic);
        mWvMonth.setCyclic(cyclic);
        mWvDay.setCyclic(cyclic);
        wv_hours.setCyclic(cyclic);
        wv_minutes.setCyclic(cyclic);
        wv_seconds.setCyclic(cyclic);
    }


    //获取显示的时间
    public String getTime() {
        StringBuilder sb = new StringBuilder();
        Integer year = mYearAdapter.getItem(mWvYear.getCurrentItem());
        Integer month = mMonthAdapter.getItem(mWvMonth.getCurrentItem());

        int day;
        Object dayObject = mDayAdapter.getItem(mWvDay.getCurrentItem());
        if (dayObject instanceof DayModel) {
            day = ((DayModel) dayObject).getDay();
        } else {
            day = (int) dayObject;
        }
        int hours = mHoursAdapter.getItem(wv_hours.getCurrentItem());
        int minutes = mMinutesAdapter.getItem(wv_minutes.getCurrentItem());
        int seconds = mSecondAdapter.getItem(wv_seconds.getCurrentItem());

        sb.append(year).append(".")
                .append(month).append(".")
                .append(day).append(" ")
                .append(hours).append(":")
                .append(minutes).append(":")
                .append(seconds);
        return sb.toString();
    }


    public View getView() {
        return view;
    }

    protected Calendar mStartDate;
    protected Calendar mEndDate;

    public int getStartYear() {
        if (mStartDate != null) {
            return mStartDate.get(Calendar.YEAR);
        }

        return DEFAULT_START_YEAR;
    }

    public int getEndYear() {
        if (mEndDate != null) {
            int startYear = getStartYear();
            if (mEndDate.get(Calendar.YEAR) < startYear) {
                return startYear;
            }
            return mEndDate.get(Calendar.YEAR);
        }

        return DEFAULT_END_YEAR;
    }

    public int getStartMonth(int currentYear) {
        int startYear;
        if (mStartDate != null) {
            startYear = mStartDate.get(Calendar.YEAR);
            if (startYear == currentYear) {
                return mStartDate.get(Calendar.MONTH) + 1;
            }
        }

        return DEFAULT_START_MONTH;
    }

    public int getEndMonth(int currentYear) {
        int endYear;
        if (mEndDate != null) {
            endYear = mEndDate.get(Calendar.YEAR);
            if (endYear == currentYear) {
                return mEndDate.get(Calendar.MONTH) + 1;
            }
        }
        return DEFAULT_END_MONTH;
    }

    public int getStartDay(int currentYear, int currentMonth) {
        int startYear;
        int startMonth;
        if (mStartDate != null) {
            startYear = mStartDate.get(Calendar.YEAR);
            startMonth = mStartDate.get(Calendar.MONTH) + 1;
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    return mStartDate.get(Calendar.DAY_OF_MONTH);
                }
            }
        }
        return DEFAULT_START_DAY;
    }

    public int getEndDay(int currentYear, int currentMonth) {
        int startYear;
        int startMonth;
        if (mEndDate != null) {
            startYear = mEndDate.get(Calendar.YEAR);
            startMonth = mEndDate.get(Calendar.MONTH) + 1;
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    return mEndDate.get(Calendar.DAY_OF_MONTH);
                }
            }
        }

        int endDay;
        if (list_big.contains(String.valueOf(currentMonth))) {
            endDay = 31;
        } else if (list_little.contains(String.valueOf(currentMonth))) {
            endDay = 30;
        } else {    // 闰年
            if (isLeapYear(currentYear)) {
                endDay = 29;
            } else {
                endDay = 28;
            }
        }
        return endDay;
    }

    public int getStartHours(int currentYear, int currentMonth, int day) {

        int startYear;
        int startMonth;
        if (mStartDate != null) {
            startYear = mStartDate.get(Calendar.YEAR);
            startMonth = mStartDate.get(Calendar.MONTH) + 1;
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if (mStartDate.get(Calendar.DAY_OF_MONTH) == day) {
                        return mStartDate.get(Calendar.HOUR_OF_DAY);
                    }
                }
            }
        }


        return DEFAULT_START_HOURS;
    }

    public int getEndHours(int currentYear, int currentMonth, int day) {
        int startYear;
        int startMonth;
        if (mEndDate != null) {
            startYear = mEndDate.get(Calendar.YEAR);
            startMonth = mEndDate.get(Calendar.MONTH) + 1;
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if (mEndDate.get(Calendar.DAY_OF_MONTH) == day) {
                        return mEndDate.get(Calendar.HOUR_OF_DAY);
                    }
                }
            }
        }
        return DEFAULT_END_HOURS;
    }

    public int getStartMinutes(int currentYear, int currentMonth, int currentDay,int currentHours) {
        int startYear;
        int startMonth;
        int startDay;
        if (mStartDate != null) {
            startYear = mStartDate.get(Calendar.YEAR);
            startMonth = mStartDate.get(Calendar.MONTH) + 1;
            startDay = mStartDate.get(Calendar.DAY_OF_MONTH);
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if(startDay == currentDay){
                        if (mStartDate.get(Calendar.HOUR_OF_DAY) == currentHours) {
                            return mStartDate.get(Calendar.MINUTE);
                        }
                    }
                }
            }
        }
        return DEFAULT_START_MINUTES;
    }

    public int getEndMinutes(int currentYear, int currentMonth, int currentDay,int currentHours) {
        int startYear;
        int startMonth;
        int startDay;
        if (mEndDate != null) {
            startYear = mEndDate.get(Calendar.YEAR);
            startMonth = mEndDate.get(Calendar.MONTH) + 1;
            startDay = mEndDate.get(Calendar.DAY_OF_MONTH);
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if(startDay == currentDay){
                        if (mEndDate.get(Calendar.HOUR_OF_DAY) == currentHours) {
                            return mEndDate.get(Calendar.MINUTE);
                        }
                    }
                }
            }
        }
        return DEFAULT_END_MINUTES;
    }

    public int getStartSeconds(int currentYear, int currentMonth, int currentDay,int currentHours,int currentMinutes){
        int startYear;
        int startMonth;
        int startDay;
        int startHours;
        if (mStartDate != null) {
            startYear = mStartDate.get(Calendar.YEAR);
            startMonth = mStartDate.get(Calendar.MONTH) + 1;
            startDay = mStartDate.get(Calendar.DAY_OF_MONTH);
            startHours = mStartDate.get(Calendar.HOUR_OF_DAY);
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if(startDay == currentDay){
                        if(startHours == currentHours){
                            if (mStartDate.get(Calendar.MINUTE) == currentMinutes) {
                                return mStartDate.get(Calendar.SECOND);
                            }
                        }
                    }
                }
            }
        }
        return DEFAULT_START_SECONDS;
    }

    public int getEndSeconds(int currentYear, int currentMonth, int currentDay,int currentHours,int currentMinutes){
        int startYear;
        int startMonth;
        int startDay;
        int startHours;
        if (mEndDate != null) {
            startYear = mEndDate.get(Calendar.YEAR);
            startMonth = mEndDate.get(Calendar.MONTH) + 1;
            startDay = mEndDate.get(Calendar.DAY_OF_MONTH);
            startHours = mEndDate.get(Calendar.HOUR_OF_DAY);
            if (startYear == currentYear) {
                if (startMonth == currentMonth) {
                    if(startDay == currentDay){
                        if(startHours == currentHours){
                            if (mEndDate.get(Calendar.MINUTE) == currentMinutes) {
                                return mEndDate.get(Calendar.SECOND);
                            }
                        }
                    }
                }
            }
        }
        return DEFAULT_END_SECONDS;
    }

    public void setRangDate(Calendar startDate, Calendar endDate) {
        this.mStartDate = startDate;
        this.mEndDate = endDate;
        initSolarView();
    }

    /**
     * 设置间距倍数,但是只能在1.0-4.0f之间
     *
     * @param lineSpacingMultiplier
     */
    public void setLineSpacingMultiplier(float lineSpacingMultiplier) {
        mWvDay.setLineSpacingMultiplier(lineSpacingMultiplier);
        mWvMonth.setLineSpacingMultiplier(lineSpacingMultiplier);
        mWvYear.setLineSpacingMultiplier(lineSpacingMultiplier);
        wv_hours.setLineSpacingMultiplier(lineSpacingMultiplier);
        wv_minutes.setLineSpacingMultiplier(lineSpacingMultiplier);
        wv_seconds.setLineSpacingMultiplier(lineSpacingMultiplier);
    }

    /**
     * 设置分割线的颜色
     *
     * @param dividerColor
     */
    public void setDividerColor(int dividerColor) {
        mWvDay.setDividerColor(dividerColor);
        mWvMonth.setDividerColor(dividerColor);
        mWvYear.setDividerColor(dividerColor);
        wv_hours.setDividerColor(dividerColor);
        wv_minutes.setDividerColor(dividerColor);
        wv_seconds.setDividerColor(dividerColor);
    }

    /**
     * 设置分割线的类型
     *
     * @param dividerType
     */
    public void setDividerType(WheelView.DividerType dividerType) {
        mWvDay.setDividerType(dividerType);
        mWvMonth.setDividerType(dividerType);
        mWvYear.setDividerType(dividerType);
        wv_hours.setDividerType(dividerType);
        wv_minutes.setDividerType(dividerType);
        wv_seconds.setDividerType(dividerType);
    }

    /**
     * 设置分割线之间的文字的颜色
     *
     * @param textColorCenter
     */
    public void setTextColorCenter(int textColorCenter) {
        mWvDay.setTextColorCenter(textColorCenter);
        mWvMonth.setTextColorCenter(textColorCenter);
        mWvYear.setTextColorCenter(textColorCenter);
        wv_hours.setTextColorCenter(textColorCenter);
        wv_minutes.setTextColorCenter(textColorCenter);
        wv_seconds.setTextColorCenter(textColorCenter);
    }

    /**
     * 设置分割线以外文字的颜色
     *
     * @param textColorOut
     */
    public void setTextColorOut(int textColorOut) {
        mWvDay.setTextColorOut(textColorOut);
        mWvMonth.setTextColorOut(textColorOut);
        mWvYear.setTextColorOut(textColorOut);
        wv_hours.setTextColorOut(textColorOut);
        wv_minutes.setTextColorOut(textColorOut);
        wv_seconds.setTextColorOut(textColorOut);
    }

    /**
     * @param isCenterLabel 是否只显示中间选中项的
     */
    public void isCenterLabel(boolean isCenterLabel) {
        mWvDay.isCenterLabel(isCenterLabel);
        mWvMonth.isCenterLabel(isCenterLabel);
        mWvYear.isCenterLabel(isCenterLabel);
        wv_hours.isCenterLabel(isCenterLabel);
        wv_minutes.isCenterLabel(isCenterLabel);
        wv_seconds.isCenterLabel(isCenterLabel);
    }

    public void setSelectChangeCallback(ISelectTimeCallback mSelectChangeCallback) {
        this.mSelectChangeCallback = mSelectChangeCallback;
    }

    public void setItemsVisible(int itemsVisibleCount) {
        mWvDay.setItemsVisibleCount(itemsVisibleCount);
        mWvMonth.setItemsVisibleCount(itemsVisibleCount);
        mWvYear.setItemsVisibleCount(itemsVisibleCount);
        wv_hours.setItemsVisibleCount(itemsVisibleCount);
        wv_minutes.setItemsVisibleCount(itemsVisibleCount);
        wv_seconds.setItemsVisibleCount(itemsVisibleCount);
    }

    public void setAlphaGradient(boolean isAlphaGradient) {
        mWvDay.setAlphaGradient(isAlphaGradient);
        mWvMonth.setAlphaGradient(isAlphaGradient);
        mWvYear.setAlphaGradient(isAlphaGradient);
        wv_hours.setAlphaGradient(isAlphaGradient);
        wv_minutes.setAlphaGradient(isAlphaGradient);
        wv_seconds.setAlphaGradient(isAlphaGradient);
    }
}
